package table_host;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;

import com.sam.widget.FontTextView;
import com.sam.widget.FootNavBar;

import adapter.HistortRecordAdapter;
import tangyaxin.www.saoerweima.R;

/**
 * Created by Administrator on 2016/6/27.
 */
public class MainTableHostActivity extends TabActivity {
    private TabHost tabHost;
    private FootNavBar footNavBar;
    private static final String TAG_TAB_SCAN="扫描";
    private static final String TAG_TAB_MAKE="制作";
    private static final String TAG_TAB_HISTORT="历史";
    private static final String TAG_TAB_SETTING="设置";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.table_host_main);
        findview();
        initview();
    }
    private void findview() {
            tabHost= (TabHost) findViewById(android.R.id.tabhost);
             footNavBar= (FootNavBar) findViewById(R.id.foot_nav_bar);
    }

    private void initview() {
        footNavBar.setOnNavItemChangedListener(onNavItemChangedListener);
//        footNavBar.setCurrentPosition(0);
        footNavBar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainTableHostActivity.this,ScanActivity.class));
            }
        });

        if(tabHost == null) throw new NullPointerException(" ");
         tabHost.setup(getLocalActivityManager());
          tabHost.addTab(tabHost.newTabSpec(TAG_TAB_SCAN).setContent(new Intent(this,ScanActivity.class)).setIndicator(TAG_TAB_SCAN));
          tabHost.addTab(tabHost.newTabSpec(TAG_TAB_HISTORT).setContent(new Intent(this, HistortActivity.class)).setIndicator(TAG_TAB_HISTORT));
          tabHost.addTab(tabHost.newTabSpec(TAG_TAB_MAKE).setContent(new Intent(this,MakeActivity.class)).setIndicator(TAG_TAB_MAKE));
          tabHost.addTab(tabHost.newTabSpec(TAG_TAB_SETTING).setContent(new Intent(this,SettingActivity.class)).setIndicator(TAG_TAB_SETTING));
          tabHost.setCurrentTabByTag(TAG_TAB_SCAN);
    }

    FootNavBar.OnNavItemChangedListener onNavItemChangedListener=new FootNavBar.OnNavItemChangedListener() {
        private static final int ONE=0;
        private static final int TWO=1;
        private static final int THREE=2;
        private static final int FOUR=3;
        @Override
        public void onNavItemChanged(FontTextView[] items, FontTextView item, int posistion) {
                for (int i=0;i<4;i++)items[i].setAlpha(0.5f);
            switch (posistion){
                case ONE:
                    tabHost.setCurrentTabByTag(TAG_TAB_SCAN);
                    item.setAlpha(1.0f);
                    break;
                case TWO:
                    tabHost.setCurrentTabByTag(TAG_TAB_HISTORT);
                    item.setAlpha(1.0f);
                    break;
                case THREE:
                    tabHost.setCurrentTabByTag(TAG_TAB_MAKE);
                    item.setAlpha(1.0f);
                    break;
                case FOUR:
                    tabHost.setCurrentTabByTag(TAG_TAB_SETTING);
                    item.setAlpha(1.0f);
                    break;
            }
        }
    };
}
